package com.xz.knowledgeDuplication.pattern.command;

import lombok.AllArgsConstructor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 服务员(调用者角色)
 *
 * @author 召
 * @date 2022-03-23 22:18:58
 */
public class Waiter {

    private List<Command> commands = new ArrayList<Command>();

    public void setCommands(Command command) {
        commands.add(command);
    }

    /**
     * 订单来了 调用命令
     */
    public void orderUp() {
        if (commands != null && commands.size() != 0) {
            for (Iterator<Command> iterator = commands.iterator(); iterator.hasNext(); ) {
                Command command = iterator.next();
                command.execute();
                iterator.remove();
            }
        }
    }
}
